package com.wjk.kylin.rpc.core.netty.params;


import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author wjk
 */
public abstract class AbstractMessage implements Serializable {
    private static final long serialVersionUID = 1L;

    public static Class<? extends AbstractMessage> getMessageClass(int messageType) {
        return MESSAGE_CLASSES.get(messageType);
    }

    /**
     * 指令类型 消息类型
     *
     * @return
     */
    public abstract int getMessageType();

    /**
     * 请求类型 byte 值
     */
    public static final int RPC_MESSAGE_TYPE_REQUEST = 0;
    /**
     * 响应类型 byte 值
     */
    public static final int RPC_MESSAGE_TYPE_RESPONSE = 1;

    /**
     * 心跳
     */
    public static final int PING_MESSAGE = 2;

    private static final Map<Integer, Class<? extends AbstractMessage>> MESSAGE_CLASSES = new HashMap<>();

    static {
        MESSAGE_CLASSES.put(RPC_MESSAGE_TYPE_REQUEST, RpcRequest.class);
        MESSAGE_CLASSES.put(RPC_MESSAGE_TYPE_RESPONSE, RpcResponse.class);
        MESSAGE_CLASSES.put(PING_MESSAGE, PingMessage.class);
    }
}